
import * as schedule from 'node-schedule';
import { Injectable } from '@nestjs/common';
import * as _ from 'lodash';
import { dumpMongodbTask } from '../dump/dumpMongodbTask';

@Injectable()
export class TimeTaskService {
    constructor() {}

    startGlobalTask() {
        _.forEach(schedule.scheduledJobs, schedule.cancelJob);

        // 运行时间：凌晨2点
        let rule = new schedule.RecurrenceRule();
        rule.hour = 2;
        rule.minute = 0;
        rule.second = 0;
        // [1] 数据库备份
        schedule.scheduleJob(rule, dumpMongodbTask);
        // [2] 对已到到期时间的新书，删除并创建对应的审核记录
        // schedule.scheduleJob(rule, this.recordService.checkPresaleArrivals);
    }
}
